package com.luguz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luguz.common.Result;
import com.luguz.common.dto.LoginDto;
import com.luguz.pojo.User;
import com.luguz.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @author Guz
 * @create 2022-02--25 21:03
 */
@Controller
public class UserLoginController {
    @Autowired
    UserServiceImpl userService;

    @PostMapping("/login")
    public Object userLogin(@Validated @RequestBody LoginDto loginDto){
        User user = userService.getOne(new QueryWrapper<User>().eq("username", loginDto.getUsername()));
        if(user.getPassword().equals(loginDto.getPassword())){
            return Result.succ("登陆成功",user);
        }else {
            return Result.fail("用户名或密码错误");
        }
    }
}
